package cn.flying.system.service.cm.impl;

import javax.annotation.Resource;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import cn.flying.system.common.enums.StatusEnum;
import cn.flying.system.domain.cm.CmDictCode;
import cn.flying.system.domain.cm.CmDictCodeExample;
import cn.flying.system.mapper.cm.CmDictCodeMapper;
import cn.flying.system.service.cm.CmCodeService;

/**
 * @description:
 * @author: lvyong
 * @date: 2022年05月27日 18:31
 * @version: 1.0
 */
@Service
public class CmCodeServiceImpl implements CmCodeService {

    @Resource
    private CmDictCodeMapper cmDictCodeMapper;

    /**
     * 根据枚举类型查询枚举字典
     *
     * @param type
     * @return
     */
    @Override
    public Map<String, String> getCodeList(String type) {
        CmDictCodeExample example = new CmDictCodeExample();
        CmDictCodeExample.Criteria criteria = example.createCriteria();
        criteria.andDictTypeEqualTo(type);
        criteria.andStatusEqualTo(StatusEnum.STATUS_Y.getCode());
        List<CmDictCode> list = cmDictCodeMapper.selectByExample(example);
        Map<String, String> map = new HashMap<>();
        for (CmDictCode dictCode : list) {
            map.put(dictCode.getCode(), dictCode.getText());
        }
        return map;
    }
}
